package com.cx.interact.client.admin.controller.lottery;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cx.base.apiModel.ApiModel;
import com.cx.base.autoDoc.annotations.AutoDocField;
import com.cx.base.autoDoc.annotations.AutoDocMethod;
import com.cx.base.autoDoc.annotations.AutoDocType;
import com.cx.base.controller.BaseController;
import com.cx.base.exception.SoaException;
import com.cx.interact.interfaces.lottery.dto.lottery.PrizeDTO;
import com.cx.interact.interfaces.lottery.dto.lottery.PrizeTypeDTO;
import com.cx.interact.interfaces.lottery.service.test.PrizeService;

/**
 * cenxi 2017-01-12
 * */
@RequestMapping("lottery")
@Controller
@AutoDocType("抽奖信息")
public class LotteryController extends BaseController{

	@Resource
	private PrizeService prizeService;
	
	@RequestMapping("getPrizeType")
	@ResponseBody
	@AutoDocMethod(name = "查询活动奖项类别列表",  desc="",resClazz = PrizeTypeDTO.class,resSet="list")
	public ApiModel getPrizeType(){
		try {
			List<PrizeTypeDTO> list = prizeService.getPrizeType();
			if(list != null && list.size() > 0){
				return buildSuccMsg(list);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return buildErrorMsg(null, DATA_ERROR, "查询活动奖项类别，出错");
	}
	
	@RequestMapping("saveOrUpdatePrize")
	@ResponseBody
	@AutoDocMethod(name = "保存或更新活动奖项信息列表",  desc="actId,prizeTypeCode 为必传；prizeId不为空则更新",resClazz = PrizeDTO.class)
	public ApiModel saveOrUpdatePrize(PrizeDTO prize){
		try {
			Boolean flag = prizeService.saveOrUpdatePrize(prize);
			if(flag){
				return buildSuccMsg(null);
			}
		} catch (SoaException e) {
			e.printStackTrace();
		}
		
		return buildErrorMsg(null, DATA_ERROR, "保存或更新活动奖项，出错");
	}
	
	@RequestMapping("getPrize")
	@ResponseBody
	@AutoDocMethod(name = "查询活动奖项信息列表",  desc="actId 为必传",resClazz = PrizeDTO.class,resSet="list")
	public ApiModel getPrize(@AutoDocField("活动ID") Integer actId){
		try {
			List<PrizeDTO> list = prizeService.getPrize(actId);
			if(list != null && list.size() > 0){
				return buildSuccMsg(list);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return buildErrorMsg(null, DATA_ERROR, "查询活动奖项信息，出错");
	}
	
	@RequestMapping("getPrize")
	@ResponseBody
	@AutoDocMethod(name = "删除活动奖项",  desc="actId prizeId 为必传")
	public ApiModel delPrize(@AutoDocField("活动ID") Integer actId,@AutoDocField("奖项ID") Integer prizeId){
		try {
			Boolean flag = prizeService.delPrize(actId, prizeId);
			if(flag){
				return buildSuccMsg(null);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return buildErrorMsg(null, DATA_ERROR, "删除活动奖项，出错");
	}
	
	
}
